﻿/*
 * Copyright (C) 2012 TheLionsRoar <thelionwillalwaysroar@gmail.com>
 * Copyright (C) 2012 Jedrix <jedrix2454@gmail.com>
 * 
 * This file is part of the LEO Game Library.
 * 
 * LEO is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * LEO is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have receieved a copy of the GNU General Public License
 * along with LEO. If not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace LEO.Framework {
    public class Particle : Drawable {
        public Texture2D ParticleIcon { get; set; }
        public bool Emitting { get; set; }
        public Color Color { get; set; }
        public Vector2 Velocity { get; set; }
        public float Scale { get; set; }
        public float TimeToLive { get; set; }
        public float LifeSpeed { get; set; }

        public Particle(Texture2D particle, Color color, Vector2 position, float timeToLive, float lifeSpeed, float scale, Vector2 velocity) {
            ParticleIcon = particle;
            Color = color;
            TimeToLive = timeToLive;
            LifeSpeed = lifeSpeed;
            Scale = scale;
            Velocity = velocity;
            Emitting = true;
            Visible = true;
            Rotation = 0;
            Position = position;
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gameTime) {
            if(Visible) {
                TimeToLive -= LifeSpeed;
                Position += Velocity;
                Rotation += 0.1f;
            }
            base.Update(gameTime);
        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) {
            if(Visible) {
                Rectangle sourceRectangle = new Rectangle(0, 0, ParticleIcon.Width, ParticleIcon.Height);
                Vector2 origin = new Vector2(ParticleIcon.Width / 2, ParticleIcon.Height / 2);

                spriteBatch.Draw(ParticleIcon, Position, sourceRectangle, Color, Rotation, origin, Scale,
                                 SpriteEffects.None, 0f);
            }
        }
    }
}
